package sk.xorty.si;

import org.apache.log4j.Logger;
import org.springframework.integration.annotation.Filter;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Map;

@Component
public class ProductFilter {

    @Filter
    public Boolean filter(Map<?, ?> map) {
        String content = map.get("content").toString();
        String[] contents = content.split(";");

        System.out.println("======== FILTERING MESSAGES ========");
        boolean found = contents[MessageTypes.TYPE_INDEX].equalsIgnoreCase(MessageTypes.TYPE_INVENTORY)
                || contents[MessageTypes.TYPE_INDEX].equalsIgnoreCase(MessageTypes.TYPE_ORDER)
                || contents[MessageTypes.TYPE_INDEX].equalsIgnoreCase(MessageTypes.TYPE_SALES);

        if (found) {
            System.out.println("\t=> Filtered channel: " + Arrays.toString(contents));
        } else {
            System.out.println("\t=> Rejected channel: " + Arrays.toString(contents));
        }

        return found;
    }

}
